package com.bocai.kelalacar.ui.car.main.act;


import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bocai.kelalacar.App;
import com.bocai.kelalacar.R;
import com.bocai.kelalacar.base.BaseActivity;
import com.bocai.kelalacar.bean.MainListBean;
import com.bocai.kelalacar.bean.PhoneTypeBean;
import com.bocai.kelalacar.bean.UserBean;
import com.bocai.kelalacar.ui.car.main.contract.MainContract;
import com.bocai.kelalacar.ui.car.main.module.MainModule;
import com.bocai.kelalacar.ui.car.main.presenter.MainPresenter;
import com.bocai.kelalacar.ui.car.order.act.MyCarOrderActivity;
import com.bocai.kelalacar.ui.car.set.act.CarManageActivity;
import com.bocai.kelalacar.ui.car.set.act.CertificationInformationStateActivity;
import com.bocai.kelalacar.ui.car.set.act.DriverMangerActivity;
import com.bocai.kelalacar.ui.car.set.act.MyWalletActivity;
import com.bocai.kelalacar.ui.car.set.act.ServiceMarginActivity;
import com.bocai.kelalacar.ui.car.set.act.SetActivity;
import com.bocai.kelalacar.ui.driver.set.act.DriverCertificationInformationStateActivity;
import com.bocai.kelalacar.util.SP;
import com.bocai.kelalacar.util.ToastUitl;
import com.bumptech.glide.Glide;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by yuanfei on 2017/6/6.
 */

public class UserActivity extends BaseActivity implements MainContract.view,View.OnClickListener{

    @BindView(R.id.img_right)
    ImageView imgRight;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.head_img)
    CircleImageView headImg;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.ll_my_order)
    LinearLayout llMyOrder;
    @BindView(R.id.ll_my_wallet)
    LinearLayout llMyWallet;
    @BindView(R.id.ll_my_certification)
    LinearLayout llMyCertification;
    @BindView(R.id.ll_car_manage)
    LinearLayout llCarManage;
    @BindView(R.id.ll_driver_manage)
    LinearLayout llDriverManage;
    @BindView(R.id.ll_my_invoice)
    LinearLayout llMyInvoice;
    @BindView(R.id.ll_set)
    LinearLayout llSet;
    @Inject
    MainPresenter presenter;

    @Override
    public int getLayoutId() {
        return R.layout.act_team_user;
    }

    @Override
    public void initPresenter() {
        App.get(this).getAppComponent().addSub(new MainModule(this)).inject(this);
    }

    @Override
    public void initView() {
        llMyOrder.setOnClickListener(this);
        llMyInvoice.setOnClickListener(this);
        llSet.setOnClickListener(this);
        llMyCertification.setOnClickListener(this);
        llMyWallet.setOnClickListener(this);
        llCarManage.setOnClickListener(this);
        llDriverManage.setOnClickListener(this);
        imgRight.setOnClickListener(this);

        tvName.setText(SP.get(mContext,"PhoneNumber","").toString());
        Glide.with(mContext).load(SP.get(mContext,"Avatar2","").toString()).error(R.mipmap.head_img).into(headImg);

        if ((int)SP.get(mContext,"MemberType",0) == 3){
            llDriverManage.setVisibility(View.GONE);
            llCarManage.setVisibility(View.GONE);
        }else {
            llDriverManage.setVisibility(View.VISIBLE);
            llCarManage.setVisibility(View.VISIBLE);
        }
        if ((int)SP.get(mContext,"ApprovalStatus",0) == 1){
            presenter.getUser();
        }
    }

    @Override
    public void getCode(String code) {

    }

    @Override
    public void getType(PhoneTypeBean typeBean) {

    }

    @Override
    public void getUser(UserBean userBean) {
        if (userBean == null||userBean.getId() == null){

        }else {
            SP.putUser(this, userBean);
            tvName.setText(SP.get(this,"PhoneNumber","").toString());
            Glide.with(this).load(SP.get(this,"Avatar2","").toString()).error(R.mipmap.head_img).into(headImg);
        }
    }

    @Override
    public void setBtnCode(int index) {

    }

    @Override
    public void getHomeListSuccess(MainListBean bean) {

    }

    @Override
    public void showLoading(String title) {
        startProgressDialog(title);
    }

    @Override
    public void stopLoading() {
        stopProgressDialog();
    }

    @Override
    public void showErrorTip(String msg) {
        showErrorTip(msg);
    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(R.anim.without, R.anim.user_close);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_my_invoice:
                startActivity(new Intent(this, ServiceMarginActivity.class));
                break;
            case R.id.ll_set:
                startActivityForResult(new Intent(this, SetActivity.class),3);
                break;
            case R.id.ll_my_certification:
                if ((int) SP.get(this, "MemberType", 0) == 3) {
                    startActivity(new Intent(this, DriverCertificationInformationStateActivity.class));
                } else {
                    startActivity(new Intent(this, CertificationInformationStateActivity.class));
                }
                break;
            case R.id.ll_my_order:
                if ((int)SP.get(this,"ApprovalStatus",0) == 0){
                    ToastUitl.showShort("认证未申请");
                } else if ((int)SP.get(this,"ApprovalStatus",0) == -1){
                    ToastUitl.showShort("审核未通过");
                }else if ((int)SP.get(this,"ApprovalStatus",0) == 1){
                    ToastUitl.showShort("审核中");
                }else {
                    startActivity(new Intent(this, MyCarOrderActivity.class));
                }
                break;
            case R.id.ll_my_wallet:
                if ((int)SP.get(this,"ApprovalStatus",0) == 0){
                    ToastUitl.showShort("认证未申请");
                } else if ((int)SP.get(this,"ApprovalStatus",0) == -1){
                    ToastUitl.showShort("审核未通过");
                }else if ((int)SP.get(this,"ApprovalStatus",0) == 1){
                    ToastUitl.showShort("审核中");
                }else {
                    startActivity(new Intent(this, MyWalletActivity.class));
                }
                break;
            case R.id.ll_car_manage:
                if ((int)SP.get(this,"ApprovalStatus",0) == 0){
                    ToastUitl.showShort("认证未申请");
                } else if ((int)SP.get(this,"ApprovalStatus",0) == -1){
                    ToastUitl.showShort("审核未通过");
                }else if ((int)SP.get(this,"ApprovalStatus",0) == 1){
                    ToastUitl.showShort("审核中");
                }else {
                    startActivity(new Intent(this, CarManageActivity.class));
                }
                break;
            case R.id.ll_driver_manage:
                if ((int)SP.get(this,"ApprovalStatus",0) == 0){
                    ToastUitl.showShort("认证未申请");
                } else if ((int)SP.get(this,"ApprovalStatus",0) == -1){
                    ToastUitl.showShort("审核未通过");
                }else if ((int)SP.get(this,"ApprovalStatus",0) == 1){
                    ToastUitl.showShort("审核中");
                }else {
                    startActivity(new Intent(this, DriverMangerActivity.class));
                }
                break;
            case R.id.img_right:
                finish();
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 3){
            tvName.setText(SP.get(mContext,"PhoneNumber","").toString());
            Glide.with(mContext).load(SP.get(mContext,"Avatar2","").toString()).error(R.mipmap.head_img).into(headImg);
        }
    }
}
